import { createApp } from 'vue'

//导入路由
import router from "./router/router.js";

//导入element组件
import ElementPlus from 'element-plus'

//导入国际化中文包
import zhCn from 'element-plus/es/locale/lang/zh-cn'

//导入element的css样式
import 'element-plus/dist/index.css'

import * as ElementPlusIconsVue from '@element-plus/icons-vue'

//导入App组件（地基）
import App from './App.vue'
import { doGet } from "./http/httpRequest.js";

//导入图标
let app = createApp(App)

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

app.directive("hasPermission", (el, binding) => {


    doGet("/api/login/info", {}).then(resp => {
        let user = resp.data.data;
        let permissionList = user.permissionList;

        let flag = false;

        for (let key in permissionList) {
            if (permissionList[key] === binding.value) {
                flag = true;
                break;
            }
        }

        if (!flag) {
            el.style.display = "none";
        }
    })
})

app.use(ElementPlus, { locale: zhCn, }).use(router).mount('#app')